﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DesktopGarden.Classes;

namespace DesktopGarden.Windows
{
    /// <summary>
    /// Interaction logic for PlantWindow.xaml
    /// </summary>
    public partial class PlantWindow : Window
    {
        public FlowerInstance CurrentPlant;
        public List<FlowerInstance> FlowerCatalog;
        public int iIndex = 0;
        public bool bEditPlant = false;

        public PlantWindow()
        {
            InitializeComponent();
        }

        public void LoadComboBoxes()
        {
            cmbbxWater.Items.Add(Plant.HIGHWATER);
            cmbbxWater.Items.Add(Plant.AVGWATER);
            cmbbxWater.Items.Add(Plant.LOWWATER);
            cmbbxSun.Items.Add(Plant.FULLSUN);
            cmbbxSun.Items.Add(Plant.PARSUN);
            cmbbxSun.Items.Add(Plant.NOSUN);
            cmbbxPlantType.Items.Add(Plant.FLOWER);
            cmbbxPlantType.Items.Add(Plant.FRUIT);
            cmbbxPlantType.Items.Add(Plant.VEG);
            cmbbxSeason.Items.Add(Plant.EARLYSPRING);
            cmbbxSeason.Items.Add(Plant.SPRING);
            cmbbxSeason.Items.Add(Plant.SUMMER);
            cmbbxSeason.Items.Add(Plant.FALL);
            cmbbxLifeCycle.Items.Add(Plant.Annual);
            cmbbxLifeCycle.Items.Add(Plant.Perennial);
        }
        public void PopulateLabels()
        {
            lblPlantCatName.Content = CurrentPlant.Name;
            lblPlantType.Content = CurrentPlant.TypeofFlower;
            lblLifeCycleCat.Content = CurrentPlant.PlantLifeCycle;
            lblSeasonCat.Content = CurrentPlant.Season;
            lblSunCat.Content = CurrentPlant.Sunlight;
            lblWaterCat.Content = CurrentPlant.Waterlevel;

        }

        public void EditPlant()
        {
            if (bEditPlant)
            {
                EditBoxes.Visibility = System.Windows.Visibility.Visible;

            }
            else
            {
                EditBoxes.Visibility = System.Windows.Visibility.Hidden;

            }
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            bEditPlant = true;
            EditPlant();
        }

        private void btnRightNext(object sender, RoutedEventArgs e)
        {
            bEditPlant = false;
            EditPlant();
            PopulateLabels();
            LoadComboBoxes();
        }

        private void btnLeftNext(object sender, RoutedEventArgs e)
        {
            bEditPlant = false;
            EditPlant();
            PopulateLabels();
            LoadComboBoxes();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            bEditPlant = false;
            SaveData();
            EditPlant();
            PopulateLabels();
            LoadComboBoxes();
        }

        private void SaveData()
        {
            CurrentPlant.Name = txtName.Text;
            CurrentPlant.TypeofFlower = Convert.ToString(cmbbxPlantType.SelectedItem);
            CurrentPlant.PlantLifeCycle = Convert.ToString(cmbbxLifeCycle);
            CurrentPlant.Season = Convert.ToString(cmbbxSeason);
            CurrentPlant.Sunlight = Convert.ToString(cmbbxSun);
            CurrentPlant.Waterlevel = Convert.ToString(cmbbxWater);
        }
    }
}
